﻿var fnCustomUploadCallBack = function (data) {
    if (data != null) {
        $("#Image").attr("src", data[0].path.replace(/\\/g, "/") + "/" + data[0].name);
        mini.get("img_url").setValue(data[0].path.replace(/\\/g, "/") + "/" + data[0].name);
    }
};

$(document).ready(function () {
    //var channel_id = channel_id;
    var ctrl = mini.get("category_id");
    var url = ctrl.url.replace("@channel_id", channel_id);
    //alert(url);
    mini.get("category_id").load(url);
    ctrl.setValue(instance.category_id);



    var ue = UE.getEditor('content');
    var initContent = "<p><span style='font-size: 10px;'>&nbsp;</span></p>";
    if (getPar("id") != "") {
        initContent = instance.content;
    }
    ue.addListener("ready", function () {
        // editor准备好之后才可以使用
        ue.setContent(initContent);
    });
    var statusvalue = mini.get("status").getValue();
    var is_top = mini.get("is_top").getValue();
    var is_red = mini.get("is_red").getValue();
    var is_hot = mini.get("is_hot").getValue();
    var is_slide = mini.get("is_slide").getValue();
    var is_sys = mini.get("is_sys").getValue();
    var is_msg = mini.get("is_msg").getValue();
    if (is_msg == "") {
        mini.get("is_msg").setValue(1);
    }
    if (statusvalue == "") {
        mini.get("status").setValue(0);
    }
    if (is_top == "") {
        mini.get("is_top").setValue(1);
    }
    if (is_red == "") {
        mini.get("is_red").setValue(1);
    }
    if (is_hot == "") {
        mini.get("is_hot").setValue(1);
    }
    if (is_slide == "") {
        mini.get("is_slide").setValue(1);
    }
    if (is_sys == "") {
        mini.get("is_sys").setValue(1);
    }
    var img_url = mini.get("img_url");
    var Image = img_url.getValue();
    $("#Image").attr("src", Image);
    //var id = instance.channel_id;
    //if (id != "") {
    //    getNowFormatDate();
    //}





});



function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    instance.update_time = currentdate;
}


function fnSave() {
    var arr = [];
    arr.push(UE.getEditor('content').getContent());
    var content = arr.join("\n")
    var form = new mini.Form("#form1");
    form.validate();
    if (!form.isValid()) return;
    var form_data = form.getData();
    instance.content = content;
    fnClone(form_data, instance);
    ///数据检  查
    if (typeof (fnCustomDataCheck) != "undefined") {
        var msg = fnCustomDataCheck(instance);
        if (msg != "") {
            alert(msg);
            return;
        }
    }
    ///客制化数据保存
    if (typeof (fnCustomSave) != "undefined") {
        fnCustomSave();
        return;
    }
    if (typeof (instance) != "undefined" && instance != null) {
        var msg = mini.loading("数据保存中，请稍后......", "系统消息提醒");
        var json = mini.encode(instance);   //序列化成JSON
        $.ajax({
            url: "/extendpage/action/datasave.aspx?entity=" + const_EditEntity + "&flag=1&action=" + action,
            type: "post",
            data: { data: json },
            cache: false,
            success: function (text) {
                if (text == 1) {
                    mini.alert("数据保存成功!");
                    fnClose();
                } else {
                    mini.alert(text);
                    //alert("数据保存失败!")
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
        mini.hideMessageBox(msg);
    }
}